package com.xiaohao.server.parkmap.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xiaohao.server.parkmap.entity.CustomerReward;
import com.xiaohao.server.parkmap.mapper.CustomerRewardMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

@Service
public class CustomerRewardService {
    @Autowired
    private CustomerRewardMapper customerRewardMapper;

    public CustomerReward queryById(Integer id) {
        return customerRewardMapper.selectById(id);
    }

    public CustomerReward queryOne(CustomerReward customerReward) {
        return customerRewardMapper.selectOne(new QueryWrapper<>(customerReward));
    }

    public List<CustomerReward> query(CustomerReward customer) {
        LambdaQueryWrapper<CustomerReward> queryWrapper =
            new LambdaQueryWrapper<>(customer);
        return customerRewardMapper.selectList(queryWrapper);
    }

    public Integer delete(Integer id) {
        return customerRewardMapper.deleteById(id);
    }

    public Integer save(CustomerReward customerReward) {
        if (Objects.nonNull(customerReward) && Objects.nonNull(customerReward.getId())) {
            return customerRewardMapper.updateById(customerReward);
        } else {
            return customerRewardMapper.insert(customerReward);
        }
    }
}
